package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 查询所有的品牌数据
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> brandList = brandService.findAll();
      return Result.ok(brandList);
    }

    /**
     * 分页查询所有品牌数据
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getBrandPageList/{page}/{limit}")
    public Result getBrandPageList(@PathVariable("page") Integer pageNum,
                                   @PathVariable("limit") Integer pageSize){
        PageInfo<Brand>  brandPageList = brandService.getBrandPageList(pageNum,pageSize);
        return Result.ok(brandPageList);
    }

    /**
     * 添加品牌商标
     * @param brand
     * @return
     */
    @PostMapping("/insertBrand")
    public Result insertBrand(@RequestBody Brand brand){
         brandService.insertBrand(brand);
        return Result.ok();
    }

    /**
     * 修改品牌商标
     * @param brand
     * @return
     */
    @PutMapping("/updateBrand")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.updateBrand(brand);
        return Result.ok();
    }

    /**
     * 修改品牌商标
     * @param id
     * @return
     */
    @DeleteMapping("/deleteBrandById/{id}")
    public Result deleteBrandById(@PathVariable("id") Long id){
        brandService.deleteBrandById(id);
        return Result.ok();
    }


}
